<template>
  <div>
    <a-form-model
      ref="ruleForm"
      :model="form"
      :rules="rules"
      :label-col="labelCol"
      :wrapper-col="wrapperCol"
    >
      <a-form-model-item ref="name" label="出所时间" prop="departure">
        <a-date-picker
          :disabled="disabled"
          v-model="form.departure"
          valueFormat='YYYY-MM-DD'
          format="YYYY-MM-DD"
          style="width: 100%"
        />
      </a-form-model-item>

      <a-form-model-item label="出所详细地址" prop="detailAddress">
        <a-input
          :disabled="disabled"
          v-model="form.detailAddress"
          placeholder="请输入出所详细地址"
        />
      </a-form-model-item>

      <a-form-model-item label="通知派出所单位" prop="notifiyLocalPoliceId">
        <template style="position: relative">
            <j-select-depart :disabled="disabled" v-model="form.notifiyLocalPoliceId" :trigger-change="true" customReturnField="orgCode" :multi="true"></j-select-depart>
            <span style="position: absolute; right: -30px;top:0px">
              <a-tooltip placement="topLeft" title="选择人员出所之后，负责接收人员的市县/区派出所">
                <a-icon type="question-circle"/>
              </a-tooltip>
            </span>
          </template>
      </a-form-model-item>

      <a-form-model-item label="接收民警" prop="receiveCivilianPolice">
        <a-input
          :disabled="disabled"
          v-model="form.receiveCivilianPolice"
          placeholder="请输入接收民警名称或手机号"
        />
      </a-form-model-item>

      <a-form-model-item label="通知社区戒毒（康复）办公室" prop="drugRehabilitationOfficeId">
        <template style="position: relative">
            <j-select-depart :disabled="disabled" v-model="form.drugRehabilitationOfficeId" :trigger-change="true" customReturnField="orgCode" :multi="true"></j-select-depart>
            <span style="position: absolute; right: -30px;top:0px">
              <a-tooltip placement="topLeft" title="选择人员出所之后，负责接收人员的社区戒毒（康复）办公室">
                <a-icon type="question-circle"/>
              </a-tooltip>
            </span>
          </template>
      </a-form-model-item>

      <a-form-model-item label="办公室负责人员" prop="officePrincipal">
        <a-input
          :disabled="disabled"
          v-model="form.officePrincipal"
          placeholder="请输入负责人员名称或手机号"
        ></a-input>
      </a-form-model-item>

      <a-form-model-item label="接收家属" prop="receiveFamMember">
        <a-input
          :disabled="disabled"
          v-model="form.receiveFamMember"
          placeholder="请输入接收家属名称"
        ></a-input>
      </a-form-model-item>

      <a-form-model-item label="家属联系方式" prop="famInformation">
        <a-input
          :disabled="disabled"
          v-model="form.famInformation"
          placeholder="请输入接收家属联系电话"
        ></a-input>
      </a-form-model-item>

      <a-form-model-item label="通知内容" prop="noticeContent">
        <a-input :disabled="disabled" v-model="form.noticeContent" type="textarea" />
      </a-form-model-item>

      <a-form-model-item :wrapper-col="{ span: 14, offset: 4 }" v-if="buttonTF">
        <a-button @click="runtenFun">
          返回
        </a-button>
        <a-button style="margin-left: 10px;" type="primary" @click="onSubmit">
          确认通知
        </a-button>
        <a-button style="margin-left: 10px;" @click="localStorageFun">
          保存并退出
        </a-button>
      </a-form-model-item>
    </a-form-model>
  </div>
</template>

<script>
/*
通知
 */
import Vue from "vue";
import {USER_INFO} from "@/store/mutation-types";
import {notifyPerson, notifyUnit, queryNoticePersonOffice, queryNotifyPerson, queryUnit} from "@api/sjsk/receiveCase";

export default {
  name: "notice",
  props:['current'],
  data(){
    return {
      descriptions:this.$route.query,
      buttonTF:true,
      disabled:false,
      form:{},
      labelCol: { span: 4 },
      wrapperCol: { span: 8 },
      rules:{
        departure:[{ required: true, message: '请选择出所时间', trigger: 'change' }],
        detailAddress:[{ required: true, message: '请输入出所详细地值', trigger: 'change' }],
        notifiyLocalPoliceId:[{ required: true, message: '请选择通知派出所单位', trigger: 'change' }],
        receiveCivilianPolice:[{ required: true, message: '请输入接收民警', trigger: 'blur' }],
        drugRehabilitationOfficeId:[{ required: true, message: '请选择通知社区戒毒（康复）办公室', trigger: 'change' }],
        officePrincipal:[{ required: true, message: '请输入办公室负责人员', trigger: 'blur' }],
        receiveFamMember:[{ required: true, message: '请输入接收家属', trigger: 'blur' }],
        famInformation:[{ required: true, message: '请输入家属联系方式', trigger: 'blur' }],
        noticeContent:[{ required: true, message: '请输入通知内容', trigger: 'blur' }],
      },
      orgCode:''
    }
  },
  created() {
    this.orgCode = Vue.ls.get(USER_INFO).orgCode
    console.log(this.orgCode)
  },
  mounted() {
    this.form.id = this.$route.query.id
    console.log(this.$route.query)
    this.queryFun(this.$route.query.personId)
    this.buttonTF = this.current === 2
    // console.log(this.$store.state.holographicArchives.currentStage)
    this.disabled = !this.buttonTF
  },
  methods:{
    queryFun(val){
      queryNoticePersonOffice({id:val}).then(ser => {
        if(ser.success && ser.result){
          this.form = ser.result.noticePersonExit
          // this.$emit('leaveData',this.form)
        }
      }).catch(err => {
        console.log(err)
      })
    },
    runtenFun(){
      this.$router.go (-1)
    },
    onSubmit() {
      this.form = Object.assign(this.form,{id:this.$route.query.id},{personId:this.$route.query.personId})
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          notifyPerson(this.form).then(ser => {
            if(ser.success){
              this.disabled = true
              this.buttonTF = false
              this.$emit('currentFu',3)
              // this.$emit('leaveData',this.form)
              // this.$route.query.currentStage = 1
              // this.$store.dispatch('currentStage',1)
              this.$message.success('通知成功')
            }
          })
        } else {
          this.$message.warn('请检查你的数据')
          return false;
        }
      });
    },
    localStorageFun(){
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          //本地永久存储
          localStorage.setItem('noticeeForm',JSON.stringify(this.form))
        } else {
          this.$message.warn('请检查你的数据')
          return false;
        }
      });

    }
  }
}
</script>

<style scoped>

</style>